﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp
{
    public partial class Form18 : Form
    {
        public Form18()
        {
            InitializeComponent();
        }

        public Process[] processes;

        /// <summary>
        /// 获取所有进程
        /// </summary>
        private void OutProcess() {
            dataGridView1.Rows.Clear();
            foreach (Process process in processes) {
                int newRowIndex = dataGridView1.Rows.Add();
                DataGridViewRow row = dataGridView1.Rows[newRowIndex];
                row.Cells[0].Value = process.Id;
                row.Cells[1].Value = process.ProcessName;
            }
        }

        /// <summary>
        /// 获取所有进程信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            processes = Process.GetProcesses();
            OutProcess();
        }

        /// <summary>
        /// 获取计算器信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            processes = Process.GetProcessesByName("calc");
            OutProcess();
        }
    }
}
